package com.wise.site.adapter;

import java.util.List;

import com.wise.site.protocol.result.IndexerBarEntry;
import com.wise.site.utils.Constanct;
import com.wise.site.widget.IndexBarItemView;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class IndexerBarAdapter extends BaseAdapter {
	private List<IndexerBarEntry> mList; 

	private Context mContext;
	
	public IndexerBarAdapter(Context context){
		mContext = context;
	}
	
	public void setList(List<IndexerBarEntry> list) {
		this.mList = list;
		notifyDataSetChanged();
	}
	
	public int getRealSize() {
		if(mList == null){
			return 0;
		}
		return mList.size();
	}

	@Override
	public int getCount() {
		return mList != null ? Integer.MAX_VALUE : 0;
	}

	@Override
	public Object getItem(int index) {
		if(index < mList.size()){
			return mList.get(index);
		}
		return null;
	}

	@Override
	public long getItemId(int index) {
		if(index < mList.size()){
			return mList.get(index).id;
		}
		
		return 0;
	}
	
	@Override
	public View getView(int index, View v, ViewGroup parent) {
		IndexerBarEntry item = mList.get(index % mList.size());
		if(v == null){
			IndexBarItemView text = new IndexBarItemView(mContext, item.type == Constanct.HEADLIINE_ID);
			v = text;
		}
		
		((IndexBarItemView)v).setText(item.text);
		v.setTag(item);
		
		return v;
	}

}
